﻿
using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using XQ.SP.Model;

namespace XQ.SP.BllServices
{
    //检查详细
    public partial class UserInfoCheckBLL : BaseBll
    {

        private readonly XQ.SP.DalServices.UserInfoCheckDal dal = new XQ.SP.DalServices.UserInfoCheckDal();
        public UserInfoCheckBLL()
        { }



        // 大批量导入数据
        public bool BulkCopy(DataTable data, string batchNo, int batchSize = 5000, bool onlyUpdate = false, int timeout = 300)
        {
            return dal.BulkCopy(data, batchNo, batchSize, onlyUpdate, timeout);
        }

        #region
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool ExistsWhere(string whereSql)
        {
            return dal.ExistsWhere(whereSql);
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(long Id)
        {
            return dal.Exists(Id);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public long Add(XQ.SP.Model.UserInfoCheckItem model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 批量增加数据
        /// </summary>
        public bool AddList(List<XQ.SP.Model.UserInfoCheckItem> models)
        {
            int rows = dal.AddList(models);
            if (rows > 0)
                return true;
            else
                return false;
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(XQ.SP.Model.UserInfoCheckItem model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateByUid(XQ.SP.Model.UserInfoCheckItem model)
        {
            return dal.UpdateByUid(model);
        }

        /// <summary>
        /// 批量更新数据
        /// </summary>
        public int UpdateList(List<XQ.SP.Model.UserInfoCheckItem> models)
        {
            return dal.UpdateList(models);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(long Id)
        {

            return dal.Delete(Id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        public bool DeleteListByUid(string uidList)
        {
            return dal.DeleteListByUid(uidList);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public XQ.SP.Model.UserInfoCheckItem GetModel(long Id)
        {

            return dal.GetModel(Id);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public XQ.SP.Model.UserInfoCheckItem GetModelWhereStr(string whereSql)
        {

            return dal.GetModelWhereStr(whereSql);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere = "")
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<XQ.SP.Model.UserInfoCheckItem> GetModelList(string strWhere = "")
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得新增的数据
        /// </summary>
        public List<XQ.SP.Model.UserInfoCheckItem> GetModelListNew(string datetimeStr)
        {
            DataSet ds = dal.GetList(" Created>='" + datetimeStr + "' ");
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<XQ.SP.Model.UserInfoCheckItem> DataTableToList(DataTable dt)
        {
            List<XQ.SP.Model.UserInfoCheckItem> modelList = new List<XQ.SP.Model.UserInfoCheckItem>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                XQ.SP.Model.UserInfoCheckItem model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new XQ.SP.Model.UserInfoCheckItem();

                    if (dt.Rows[n]["No"].ToString() != "")
                    {
                        model.No = dt.Rows[n]["No"].ToString();
                    }
                    if (dt.Rows[n]["Citys"].ToString() != "")
                    {
                        model.Citys = dt.Rows[n]["Citys"].ToString();
                    }
                    if (dt.Rows[n]["Towns"].ToString() != "")
                    {
                        model.Towns = dt.Rows[n]["Towns"].ToString();
                    }
                    if (dt.Rows[n]["Village"].ToString() != "")
                    {
                        model.Village = dt.Rows[n]["Village"].ToString();
                    }
                    if (dt.Rows[n]["Name"].ToString() != "")
                    {
                        model.Name = dt.Rows[n]["Name"].ToString();
                    }
                    if (dt.Rows[n]["Sex"].ToString() != "")
                    {
                        model.Sex = dt.Rows[n]["Sex"].ToString();
                    }
                    if (dt.Rows[n]["UID"].ToString() != "")
                    {
                        model.UID = dt.Rows[n]["UID"].ToString();
                    }
                    if (dt.Rows[n]["Nation"].ToString() != "")
                    {
                        model.Nation = dt.Rows[n]["Nation"].ToString();
                    }
                    if (dt.Rows[n]["ZhiYe"].ToString() != "")
                    {
                        model.ZhiYe = dt.Rows[n]["ZhiYe"].ToString();
                    }
                    if (dt.Rows[n]["HunYing"].ToString() != "")
                    {
                        model.HunYing = dt.Rows[n]["HunYing"].ToString();
                    }
                    if (dt.Rows[n]["WenHua"].ToString() != "")
                    {
                        model.WenHua = dt.Rows[n]["WenHua"].ToString();
                    }
                    if (dt.Rows[n]["ShangHu"].ToString() != "")
                    {
                        model.ShangHu = dt.Rows[n]["ShangHu"].ToString();
                    }
                    if (dt.Rows[n]["BuNaRu"].ToString() != "")
                    {
                        model.BuNaRu = dt.Rows[n]["BuNaRu"].ToString();
                    }
                    if (dt.Rows[n]["YiNian"].ToString() != "")
                    {
                        model.YiNian = dt.Rows[n]["YiNian"].ToString();
                    }
                    if (dt.Rows[n]["CanJiaTi"].ToString() != "")
                    {
                        model.CanJiaTi = dt.Rows[n]["CanJiaTi"].ToString();
                    }
                    if (dt.Rows[n]["CanJiaJian"].ToString() != "")
                    {
                        model.CanJiaJian = dt.Rows[n]["CanJiaJian"].ToString();
                    }
                    if (dt.Rows[n]["CanJiaTime"].ToString() != "")
                    {
                        model.CanJiaTime = System.DateTime.Parse(dt.Rows[n]["CanJiaTime"].ToString());
                    }
                    if (dt.Rows[n]["JieGuo"].ToString() != "")
                    {
                        model.JieGuo = dt.Rows[n]["JieGuo"].ToString();
                    }
                    if (dt.Rows[n]["JIWang"].ToString() != "")
                    {
                        model.JiWang = dt.Rows[n]["JIWang"].ToString();
                    }
                    if (dt.Rows[n]["CaiXue"].ToString() != "")
                    {
                        model.CaiXue = dt.Rows[n]["CaiXue"].ToString();
                    }
                    if (dt.Rows[n]["FuCha"].ToString() != "")
                    {
                        model.FuCha = dt.Rows[n]["FuCha"].ToString();
                    }
                    if (dt.Rows[n]["JieGuoHIV"].ToString() != "")
                    {
                        model.JieGuoHIV = dt.Rows[n]["JieGuoHIV"].ToString();
                    }
                    if (dt.Rows[n]["WeiJianCe"].ToString() != "")
                    {
                        model.WeiJianCe = dt.Rows[n]["WeiJianCe"].ToString();
                    }
                    if (dt.Rows[n]["Desc"].ToString() != "")
                    {
                        model.Desc = dt.Rows[n]["Desc"].ToString();
                    }
                    if (dt.Rows[n]["State"].ToString() != "")
                    {
                        model.State = dt.Rows[n]["State"].ToString();
                    }
                    if (dt.Rows[n]["StateTime"].ToString() != "")
                    {
                        model.StateTime = System.DateTime.Parse(dt.Rows[n]["StateTime"].ToString());
                    }
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = Int64.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    if (dt.Rows[n]["Status"].ToString() != "")
                    {
                        model.Status = Int32.Parse(dt.Rows[n]["Status"].ToString());
                    }
                    if (dt.Rows[n]["Creator"].ToString() != "")
                    {
                        model.Creator = Int64.Parse(dt.Rows[n]["Creator"].ToString());
                    }
                    if (dt.Rows[n]["Created"].ToString() != "")
                    {
                        model.Created = System.DateTime.Parse(dt.Rows[n]["Created"].ToString());
                    }
                    if (dt.Rows[n]["Modifier"].ToString() != "")
                    {
                        model.Modifier = Int64.Parse(dt.Rows[n]["Modifier"].ToString());
                    }
                    if (dt.Rows[n]["Modified"].ToString() != "")
                    {
                        model.Modified = System.DateTime.Parse(dt.Rows[n]["Modified"].ToString());
                    }
                    if (dt.Rows[n]["Images"].ToString() != "")
                    {
                        model.Images = dt.Rows[n]["Images"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<XQ.SP.Model.UserInfoCheck2Item> DataTableToList2(DataTable dt)
        {
            List<XQ.SP.Model.UserInfoCheck2Item> modelList = new List<XQ.SP.Model.UserInfoCheck2Item>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                XQ.SP.Model.UserInfoCheck2Item model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new XQ.SP.Model.UserInfoCheck2Item();

                    if (dt.Rows[n]["No"].ToString() != "")
                    {
                        model.No = dt.Rows[n]["No"].ToString();
                    }
                    if (dt.Rows[n]["Citys"].ToString() != "")
                    {
                        model.Citys = dt.Rows[n]["Citys"].ToString();
                    }
                    if (dt.Rows[n]["Towns"].ToString() != "")
                    {
                        model.Towns = dt.Rows[n]["Towns"].ToString();
                    }
                    if (dt.Rows[n]["Village"].ToString() != "")
                    {
                        model.Village = dt.Rows[n]["Village"].ToString();
                    }
                    if (dt.Rows[n]["Name"].ToString() != "")
                    {
                        model.Name = dt.Rows[n]["Name"].ToString();
                    }
                    if (dt.Rows[n]["Sex"].ToString() != "")
                    {
                        model.Sex = dt.Rows[n]["Sex"].ToString();
                    }
                    if (dt.Rows[n]["UID"].ToString() != "")
                    {
                        model.UID = dt.Rows[n]["UID"].ToString();
                    }
                    if (dt.Rows[n]["Nation"].ToString() != "")
                    {
                        model.Nation = dt.Rows[n]["Nation"].ToString();
                    }
                    if (dt.Rows[n]["ZhiYe"].ToString() != "")
                    {
                        model.ZhiYe = dt.Rows[n]["ZhiYe"].ToString();
                    }
                    if (dt.Rows[n]["HunYing"].ToString() != "")
                    {
                        model.HunYing = dt.Rows[n]["HunYing"].ToString();
                    }
                    if (dt.Rows[n]["WenHua"].ToString() != "")
                    {
                        model.WenHua = dt.Rows[n]["WenHua"].ToString();
                    }
                    if (dt.Rows[n]["ShangHu"].ToString() != "")
                    {
                        model.ShangHu = dt.Rows[n]["ShangHu"].ToString();
                    }
                    if (dt.Rows[n]["BuNaRu"].ToString() != "")
                    {
                        model.BuNaRu = dt.Rows[n]["BuNaRu"].ToString();
                    }
                    if (dt.Rows[n]["YiNian"].ToString() != "")
                    {
                        model.YiNian = dt.Rows[n]["YiNian"].ToString();
                    }
                    if (dt.Rows[n]["CanJiaTi"].ToString() != "")
                    {
                        model.CanJiaTi = dt.Rows[n]["CanJiaTi"].ToString();
                    }
                    if (dt.Rows[n]["CanJiaJian"].ToString() != "")
                    {
                        model.CanJiaJian = dt.Rows[n]["CanJiaJian"].ToString();
                    }
                    if (dt.Rows[n]["CanJiaTime"].ToString() != "")
                    {
                        //model.CanJiaTime = dt.Rows[n]["CanJiaTime"].ToString();
                        model.CanJiaTime = System.DateTime.Parse(dt.Rows[n]["CanJiaTime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    if (dt.Rows[n]["JieGuo"].ToString() != "")
                    {
                        model.JieGuo = dt.Rows[n]["JieGuo"].ToString();
                    }
                    if (dt.Rows[n]["JIWang"].ToString() != "")
                    {
                        model.JiWang = dt.Rows[n]["JIWang"].ToString();
                    }
                    if (dt.Rows[n]["CaiXue"].ToString() != "")
                    {
                        model.CaiXue = dt.Rows[n]["CaiXue"].ToString();
                    }
                    if (dt.Rows[n]["FuCha"].ToString() != "")
                    {
                        model.FuCha = dt.Rows[n]["FuCha"].ToString();
                    }
                    if (dt.Rows[n]["JieGuoHIV"].ToString() != "")
                    {
                        model.JieGuoHIV = dt.Rows[n]["JieGuoHIV"].ToString();
                    }
                    if (dt.Rows[n]["WeiJianCe"].ToString() != "")
                    {
                        model.WeiJianCe = dt.Rows[n]["WeiJianCe"].ToString();
                    }
                    if (dt.Rows[n]["Desc"].ToString() != "")
                    {
                        model.Desc = dt.Rows[n]["Desc"].ToString();
                    }
                    if (dt.Rows[n]["State"].ToString() != "")
                    {
                        model.State = dt.Rows[n]["State"].ToString();
                    }
                    if (dt.Rows[n]["StateTime"].ToString() != "")
                    {
                        //model.StateTime = dt.Rows[n]["StateTime"].ToString();
                        model.StateTime = System.DateTime.Parse(dt.Rows[n]["StateTime"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = Int64.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    if (dt.Rows[n]["Status"].ToString() != "")
                    {
                        model.Status = Int32.Parse(dt.Rows[n]["Status"].ToString());
                    }
                    if (dt.Rows[n]["Creator"].ToString() != "")
                    {
                        model.Creator = Int64.Parse(dt.Rows[n]["Creator"].ToString());
                    }
                    if (dt.Rows[n]["Created"].ToString() != "")
                    {
                        //model.Created = dt.Rows[n]["Created"].ToString();
                        model.Created = System.DateTime.Parse(dt.Rows[n]["Created"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    if (dt.Rows[n]["Modifier"].ToString() != "")
                    {
                        model.Modifier = Int64.Parse(dt.Rows[n]["Modifier"].ToString());
                    }
                    if (dt.Rows[n]["Modified"].ToString() != "")
                    {
                        model.Modified = System.DateTime.Parse(dt.Rows[n]["Modified"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    if (dt.Rows[n]["Images"].ToString() != "")
                    {
                        model.Images = dt.Rows[n]["Images"].ToString();
                    }
                    if (dt.Rows[n]["Change"].ToString() != "")
                    {
                        model.Change = int.Parse(dt.Rows[n]["Change"].ToString());
                    }

                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }



        /// <summary>
        /// Model的属性对应赋值
        /// </summary>
        public void ModelCopy(XQ.SP.Model.UserInfoCheckItem modelOld, XQ.SP.Model.UserInfoCheckItem modelNew)
        {

            modelNew.No = modelOld.No;
            modelNew.Citys = modelOld.Citys;
            modelNew.Towns = modelOld.Towns;
            modelNew.Village = modelOld.Village;
            modelNew.Name = modelOld.Name;
            modelNew.Sex = modelOld.Sex;
            modelNew.UID = modelOld.UID;
            modelNew.Nation = modelOld.Nation;
            modelNew.ZhiYe = modelOld.ZhiYe;
            modelNew.HunYing = modelOld.HunYing;
            modelNew.WenHua = modelOld.WenHua;
            modelNew.ShangHu = modelOld.ShangHu;
            modelNew.BuNaRu = modelOld.BuNaRu;
            modelNew.YiNian = modelOld.YiNian;
            modelNew.CanJiaTi = modelOld.CanJiaTi;
            modelNew.CanJiaJian = modelOld.CanJiaJian;
            modelNew.CanJiaTime = modelOld.CanJiaTime;
            modelNew.JieGuo = modelOld.JieGuo;
            modelNew.JiWang = modelOld.JiWang;
            modelNew.CaiXue = modelOld.CaiXue;
            modelNew.FuCha = modelOld.FuCha;
            modelNew.JieGuoHIV = modelOld.JieGuoHIV;
            modelNew.WeiJianCe = modelOld.WeiJianCe;
            modelNew.Desc = modelOld.Desc;
            modelNew.State = modelOld.State;
            modelNew.StateTime = modelOld.StateTime;
            modelNew.Id = modelOld.Id;
            modelNew.Status = modelOld.Status;
            modelNew.Creator = modelOld.Creator;
            modelNew.Created = modelOld.Created;
            modelNew.Modifier = modelOld.Modifier;
            modelNew.Modified = modelOld.Modified;
            modelNew.Images = modelOld.Images;
        }


        /// <summary>
        /// 获得身份证列表
        /// </summary>
        public List<string> GetUidList(string strWhere = "")
        {
            DataSet ds = dal.GetUidList(strWhere);
            var dt = ds.Tables[0];

            List<string> modelList = new List<string>();

            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                for (int n = 0; n < rowsCount; n++)
                {
                    if (!string.IsNullOrWhiteSpace(dt.Rows[n]["UID"].ToString()))
                    {
                        modelList.Add(dt.Rows[n]["UID"].ToString());
                    }
                }
            }

            return modelList;
        }


        #endregion

    }
}

